package br.com.puertorico.model.querybuilder.sorting;

/**
 *
 * @author Daniel Camargo
 * @version 1.0.0
 */
public class MultiSortStrategy extends SortStrategy {

	private static final long serialVersionUID = 2969518334779529767L;

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * br.ufms.nin.jpa.querybuilder.api.SortStrategie#addSortItem(java
	 * .lang.String)
	 */
	@Override
	public void addSortItem(String columnName) {
		// contem no map
		if (getSortItemMap().containsKey(columnName)) {
			if (getSortItemMap().get(columnName).getAsc()) {
				getSortItemMap().get(columnName).setAsc(false);
			} else {
				getSortItemMap().remove(columnName);
				// update order
				int order = 0;
				for (SortItem item : getSortItemList()) {
					item.setOrder(order++);
				}
			}
		} else {
			SortItem item = new SortItem(columnName, true, getSortItemMap()
					.size());
			getSortItemMap().put(columnName, item);
		}
	}

}
